package com.iatinspur.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ThreadConfig {




    @Bean("myThread")
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
        int core = Runtime.getRuntime().availableProcessors();
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(core);
        threadPoolTaskExecutor.setMaxPoolSize(100);
        // threadPoolTaskExecutor.setTaskDecorator(new MdcTaskDecorator());
        //threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
        threadPoolTaskExecutor.setKeepAliveSeconds(60 * 30);
        threadPoolTaskExecutor.setQueueCapacity(5000);
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
        threadPoolTaskExecutor.initialize();
        threadPoolTaskExecutor.setThreadNamePrefix("这是线程的前缀名");
        return threadPoolTaskExecutor;
    }
}
